﻿@{
    Layout = null;
}
<style>
    .form-horizontal .form-group {
        margin-bottom: 15px;
        margin-top: 15px;
    }

    .form-group.money .btn {
        margin-left: 5px;
    }
</style>
<form class="form-horizontal" id="LLBPacket">
    <div>请为不同的用户选择流量套餐类型</div>
    <div class="form-group money">
        <div class="col-md-2 text-right">移动用户：</div>
        <div class="col-md-10" id="mobile">
            <input type="hidden" name="DataID2_YD" value="10" />
        </div>
    </div>


    <div class="form-group money">
        <div class="col-md-2 text-right">电信用户：</div>
        <div class="col-md-10" id="chinaNet">
            <input type="hidden" name="DataID3_DX" value="10" />
        </div>
    </div>


    <div class="form-group money">
        <div class="col-md-2 text-right">联通用户：</div>
        <div class="col-md-10" id="union">
            <input type="hidden" name="DataID1_LT" value="20" />
        </div>
    </div>
    <input type="hidden" name="Data_DX" id="Data_DX" value="" />
    <input type="hidden" name="Data_YD" id="Data_YD" value="" />
    <input type="hidden" name="Data_LT" id="Data_LT" value="" />
</form>
<script>
    $.get('/Market/getFlowTable', '', function (r) {
        //console.log(r)
        var rr = eval('(' + r + ')');
        //console.log(rr.result)
        $(rr.result).each(function (i, ele) {
            if (ele.company === "中国联通") {
                $(ele.flows).each(function (i, ele1) {
                    if (i == 0) {
                        $('#union').append('<span class="btn btn-success active-money" data-num="' + ele1.p + '"   data-inprice="' + ele1.inprice + '" data-id="' + ele1.id + '">' + ele1.p + '</span>');
                    }
                    else {
                        $('#union').append('<span class="btn btn-default" data-num="' + ele1.p + '"   data-inprice="' + ele1.inprice + '" data-id="' + ele1.id + '">' + ele1.p + '</span>');
                    }
                })
                $('#union').append('<span class="btn btn-default" style="color:#50AE55">' + ele.flows[0].inprice + '元</span>');
            }
            else if (ele.company === "中国移动") {
                $(ele.flows).each(function (i, ele1) {
                    if (i == 0) {
                        $('#mobile').append('<span class="btn btn-success active-money"  data-num="' + ele1.p + '"  data-inprice="' + ele1.inprice + '" data-id="' + ele1.id + '">' + ele1.p + '</span>');
                    }
                    else {
                        $('#mobile').append('<span class="btn btn-default" data-num="' + ele1.p + '"   data-inprice="' + ele1.inprice + '" data-id="' + ele1.id + '">' + ele1.p + '</span>');
                    }

                })
                $('#mobile').append('<span class="btn btn-default" style="color:#50AE55">' + ele.flows[0].inprice + '元</span>');
            }
            else {
                $(ele.flows).each(function (i, ele1) {
                    if (i == 0) {
                        $('#chinaNet').append('<span class="btn btn-success active-money" data-num="' + ele1.p + '"  data-inprice="' + ele1.inprice + '" data-id="' + ele1.id + '">' + ele1.p + '</span>');
                    }
                    else {
                        $('#chinaNet').append('<span class="btn btn-default" data-num="' + ele1.p + '"   data-inprice="' + ele1.inprice + '" data-id="' + ele1.id + '">' + ele1.p + '</span>');
                    }

                });
                $('#chinaNet').append('<span class="btn btn-default" style="color:#50AE55">' + ele.flows[0].inprice + '元</span>');
            }

        })
        $('#Data_DX').val($('#chinaNet').find('.btn-success').data('num'));
        $('#Data_YD').val($('#mobile').find('.btn-success').data('num'));
        $('#Data_LT').val($('#union').find('.btn-success').data('num'));
    })



    $('#LLBPacket div.form-group.money').on('click', 'span.btn', function () {
        $(this).siblings().removeClass('btn-success').addClass('btn-default');
        $(this).removeClass('btn-default').addClass('btn-success');
        $(this).siblings('input[type="hidden"]').val($(this).data("id"));
        $(this).parent().children('span:last').text($(this).data("inprice") + '元' + '--' + $(this).data("num"));


        $('#Data_DX').val($('#chinaNet').find('.btn-success').data('num'));
        $('#Data_YD').val($('#mobile').find('.btn-success').data('num'));
        $('#Data_LT').val($('#union').find('.btn-success').data('num'));


    });
    $('#LLBPacket .col-md-7 input[name="TotalNums"]').blur(function () {
        if ($(this).val() != '') {
            var val = parseInt($(this).val());
            var MinMoney = parseFloat($('#LLBPacket div.form-group.money #chinaNet').children('span:last').text()) * val;
            var MidMoney = parseFloat($('#LLBPacket div.form-group.money #union').children('span:last').text()) * val;
            var TotalMoney = parseFloat($('#LLBPacket div.form-group.money #mobile').children('span:last').text()) * val;
            $('#LLBPacket .col-md-7 #showMoney').val(Math.min(MinMoney, MidMoney, TotalMoney).toFixed(3) + ' ~ ' + Math.max(MinMoney, MidMoney, TotalMoney).toFixed(3)).next().val(Math.max(MinMoney, MidMoney, TotalMoney).toFixed(3));
            $('#LLBPacket .col-md-7 input[type="hidden"][name="MaxDenomination"]').val((Math.max(MinMoney, MidMoney, TotalMoney) / val).toFixed(3)).next().val((Math.min(MinMoney, MidMoney, TotalMoney) / val).toFixed(3)).next().val((Math.max(MinMoney, MidMoney, TotalMoney) / val).toFixed(3));
        }
    })


</script>